var str = '/var/www/site/Brand new document.docx'; document.write( str.replace(/\s/g, '') );
<div style="white-space:pre-wrap"> <!-- New Line --> <!-- 2 space --> This is my text </div>